package com.sendpo.zjx.sendpo.activity;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.sendpo.zjx.sendpo.R;
import com.sendpo.zjx.sendpo.domain.MerchantVideoDomain;
import com.sendpo.zjx.sendpo.domain.MerchantVideosDomain;
import com.sendpo.zjx.sendpo.utils.Tools;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;
import master.flame.danmaku.ui.widget.DanmakuView;
import tv.danmaku.ijk.media.player.IMediaPlayer;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;
import tv.danmaku.ijk.media.widget.media.AndroidMediaController;
import tv.danmaku.ijk.media.widget.media.IjkVideoView;

/**
 * Created by zjx on 2018
 */

public class WebOnlineContentActivity extends AppCompatActivity {


    MerchantVideosDomain.DataBean dataBean;
    @BindView(R.id.videoView)
    IjkVideoView videoView;
    @BindView(R.id.danmakuView)
    DanmakuView danmakuView;
    @BindView(R.id.zhibo_rl)
    RelativeLayout zhiboRl;
    @BindView(R.id.backbt)
    ImageView backbt;
    @BindView(R.id.head_actionbar)
    RelativeLayout headActionbar;
    @BindView(R.id.cir_icon)
    CircleImageView cirIcon;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.cityarea)
    TextView cityarea;
    @BindView(R.id.num_bt)
    Button numBt;
    @BindView(R.id.good_tv)
    TextView goodTv;
    @BindView(R.id.goods_iv)
    ImageView goodsIv;
    @BindView(R.id.goods_bt)
    RelativeLayout goodsBt;
    @BindView(R.id.good_tvrl)
    RelativeLayout goodTvrl;
    @BindView(R.id.edit)
    EditText edit;
    @BindView(R.id.send_bt)
    Button sendBt;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Tools.initStatus(this, R.color.black);
        setContentView(R.layout.activity_webonline_content);
        ButterKnife.bind(this);
        initComponent();
        dataBean = (MerchantVideosDomain.DataBean) getIntent().getSerializableExtra("data");
        if (dataBean != null) {
            Glide.with(this)
                    .load(dataBean.getMerchantsImg())
                    .asBitmap()
                    .error(R.drawable.nim_avatar_default)
                    .placeholder(R.drawable.nim_avatar_default)
                    .into(new SimpleTarget<Bitmap>() {
                        @Override
                        public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                            cirIcon.setImageBitmap(resource);
                        }
                    });
            name.setText("" + dataBean.getMerchantsName());
            cityarea.setText("" + dataBean.getCity() + dataBean.getArea());
            IjkMediaPlayer.loadLibrariesOnce(null);
            IjkMediaPlayer.native_profileBegin("libijkplayer.so");
            this.videoView.setVideoPath(dataBean.getUrl());
            this.videoView.setMediaController(new AndroidMediaController(this));
            this.videoView.start();
            this.videoView.changeAspectRaito(0);
            this.videoView.setOnPreparedListener(new IMediaPlayer.OnPreparedListener() {
                public void onPrepared(IMediaPlayer paramAnonymousIMediaPlayer) {
                    paramAnonymousIMediaPlayer.setLooping(true);
                    paramAnonymousIMediaPlayer.start();
                }
            });
            this.videoView.setOnCompletionListener(new IMediaPlayer.OnCompletionListener() {
                public void onCompletion(IMediaPlayer paramAnonymousIMediaPlayer) {
                }
            });
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        this.videoView.release(true);
        IjkMediaPlayer.native_profileEnd();
    }

    private void initComponent() {

    }

    @OnClick(value = {R.id.backbt})
    public void onmyClick(View v) {
        switch (v.getId()) {
            case R.id.backbt:
                finish();
                break;
        }
    }


}
